package news.controller;

import news.service.AddPublishServiceImpl;
import news.service.IAddPublishService;
import news.util.BaseHttpServlet;
import news.util.FileUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author JiangJ
 * @date 2022/3/4 17:07
 */
@WebServlet("/addPublishNews")
public class AddPublishController extends BaseHttpServlet {
    IAddPublishService iAddPublishService = new AddPublishServiceImpl();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应内容类型
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("utf-8");
        //存储各种数据信息
        String theme = request.getParameter("theme");
        String title = request.getParameter("title");
        String username = request.getParameter("username");
        String digest = request.getParameter("digest");
        String content = request.getParameter("content");
        //存储新闻
        iAddPublishService.addNews(theme, title, username, digest, content);
        //3.返回成功响应
        request.getRequestDispatcher(request.getContextPath() + "/news/suc.jsp").forward(request, response);

    }
}
